package Demo2;

import java.util.Scanner;

public class Demo20 {
    public static void main(String[] args) throws InterruptedException {
        Object lock=new Object();

        Thread t1=new Thread(()->{
            try {
                System.out.println("t1线程wait之前");
                synchronized(lock){
                    lock.wait();
                }
                System.out.println("t1线程wait之后");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });

        Thread t2=new Thread(()->{
                try {
                    System.out.println("t2线程wait之前");
                    synchronized(lock){
                    lock.wait();
                    }
                    System.out.println("t2线程wait之后");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
        });

        Thread t3=new Thread(()->{
            Scanner scanner=new Scanner(System.in);
            System.out.println("输入任意信息，唤醒所有线程");
scanner.next();
            synchronized (lock){
                lock.notifyAll();
            }
        });


        t1.start();
        t2.start();
        t3.start();


    }
}
